
from robot.api import logger

from ...assistant import FwVariables
from ...common.ui.Selector import Selector
from ...common.ui.PageElement import PageElement


class AntdPageElement(PageElement):
    def __init__(self, driver, selector_str, selector_type=Selector.CLASS_NAME):
        super(AntdPageElement, self).__init__(driver, selector_str, selector_type)
        # try:
        #     self._antd_version = self._execute_script('return antd.version;')
        # except JavascriptException as e:
        #     logger.error("Get antd version failed because {0}".format(e.msg))
        # antd 从配置文件中读，通过脚本方式读不靠普
        self._antd_version = FwVariables.get_value('ENV','antdVersion','3.25.1')

    # PageElement的click是fish组件的，使用的是script方式，react的不能用，所以重载下
    def click(self):
        try:
            self.wait_element_presence()
            self.wait_element_ready()
        except Exception as re:
            logger.error(re)
        self._get_web_element().click()

    def get_antd_version(self):
        return self._antd_version

    def is_antd_version_3x(self):
        if self._antd_version and self._antd_version.find('3.') == 0:
            return True
        return False

    def is_antd_version_4x(self):
        if self._antd_version and self._antd_version.find('4.') == 0:
            return True
        return False

